package com.ourhours.message.response;

import com.ourhours.message.response.MmsBaseResponseCode;

import java.io.Serializable;

/**
 * Created by zml on 2017/10/24.
 */
public class MmsBaseResponse<T> implements Serializable {
    private static final long serialVersionUID = 2566329586602788272L;
    private String code = MmsBaseResponseCode.SUCCESS.code;

    private String msg = MmsBaseResponseCode.SUCCESS.msg;


    /**
     * 业务结果数据
     */
    private T result;

    public MmsBaseResponse() {
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getResult() {
        return result;
    }

    public void setResult(T result) {
        this.result = result;
    }

    public MmsBaseResponse(T result) {
        this.result = result;
    }

    public MmsBaseResponse(String code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public MmsBaseResponse(String code, String msg, T result) {
        this.code = code;
        this.msg = msg;
        this.result = result;
    }

    /**
     * 成功响应信息
     * @return
     */
    public static MmsBaseResponse successResponse() {
        return new MmsBaseResponse();
    }

    /**
     * 成功响应信息
     * @return
     */
    public static <T> MmsBaseResponse<T> successResponse(T result) {
        return new MmsBaseResponse<T>(result);
    }

    /**
     * 失败响应信息
     * @return
     */
    public static MmsBaseResponse failureResponse() {
        return response(MmsBaseResponseCode.FAILURE);
    }

    public static MmsBaseResponse failureResponse(MmsBaseResponseCode code) {
        return response(code);
    }

    public static MmsBaseResponse failureResponse(String msg) {
        return new MmsBaseResponse(MmsBaseResponseCode.FAILURE.code,msg,"");
    }

    /**
     * 其他响应信息
     * @return
     */
    public static MmsBaseResponse response(MmsBaseResponseCode responseCode) {
        return new MmsBaseResponse(responseCode.code, responseCode.msg);
    }

    /**
     * 接口是否调用成功标识
     * @return
     */
    public boolean isSuccess() {
        return MmsBaseResponseCode.SUCCESS.code.equals(code);
    }
}
